package eu.vranckaert.workRegistrationWidget.activities;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.*;
import eu.vranckaert.workRegistrationWidget.R;
import eu.vranckaert.workRegistrationWidget.maps.MapsOverlayLocation;

import java.util.List;

/**
 * @author Dirk Vranckaert
 *         Date: 23-jun-2010
 *         Time: 13:51:14
 */
public class GoogleMapsActivity extends MapActivity {

    MapView mapView;
    private Double longtitude;
    private Double latitude;
    private String title;
    private String description;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();

        createMapsPointer(mapView);
    }

    private void init() {
        setContentView(R.layout.gmap);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        Bundle data = this.getIntent().getExtras();
        longtitude = data.getDouble("longtitude");
        latitude = data.getDouble("latitude");
        title = data.getString("title");
        description = data.getString("description");
    }

    private void createMapsPointer(MapView mapView) {
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.map_pin);
        MapsOverlayLocation itemizedoverlay = new MapsOverlayLocation(drawable, this);

        GeoPoint point = new GeoPoint(new Double(latitude * 1E6).intValue(),new Double(longtitude * 1E6).intValue());
        OverlayItem overlayitem2 = new OverlayItem(point, title, description);
        itemizedoverlay.addOverlay(overlayitem2);

        mapOverlays.add(itemizedoverlay);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}
